package com.liu.concurrent.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ByImplementsCallable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 自定义线程类
        MyThreadByCallable myThread = new MyThreadByCallable();
        // 适配器
        FutureTask futureTask = new FutureTask(myThread);
        // 调用
        new Thread(futureTask,"thread-").start();
        // 获取Callable返回值,会产生阻塞
        String o = (String) futureTask.get();
    }
}

/**
 * 通过实现Callable接口实现多线程
 */
class MyThreadByCallable implements Callable<String> {

    /**
     * 重写call方法
     * @return
     * @throws Exception
     */
    @Override
    public String call() throws Exception {
        return "call";
    }
}
